//
//  PopoverOtherFunctions.m
//  X-Touch2
//
//  Created by shengchao yang on 12-3-21.
//  Copyright (c) 2012年 foxhis. All rights reserved.
//

#import "PopoverOtherFunctions.h"
#import "Common.h"
#import "FileManager.h"

@implementation PopoverOtherFunctions

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [((UIButton *)[self.view viewWithTag:TagOfUIButton]) setTitle:TranslateStr(@"选择桌号") forState:UIControlStateNormal];
        [((UIButton *)[self.view viewWithTag:TagOfUIButton+1]) setTitle:TranslateStr(@"修改人数") forState:UIControlStateNormal];
        [((UIButton *)[self.view viewWithTag:TagOfUIButton+2]) setTitle:TranslateStr(@"套餐管理") forState:UIControlStateNormal];
    }
    return self;
}
- (IBAction)buttonClicked:(id)sender{
    if (AppSession.isAnimating) {
        MyNSLog(@"上一个动画还未完成...");
        return;
    }
    [AppSession playMusic:VoiceFile(@"clicked.caf")];
    if (AppSession.popController.popoverVisible) {//退出PopoverViewController
        [AppSession.popController dismissPopoverAnimated:NO];
    }
    NSInteger bid = [sender tag];
    if (bid == TagOfUIButton) {
        MyNSLog(@"开台");
        NSDictionary *infos = [NSDictionary dictionaryWithObjectsAndKeys:@"login", @"obj",nil];
        postNWithInfos(@"SysMsg_RootView_PopOutMyOrderMenuManagement", nil, infos);
    }else if(bid == TagOfUIButton + 1){
        MyNSLog(@"修改人数");
        UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
        [myTextField setBackgroundColor:[UIColor whiteColor]];
        [myTextField setTag:TagOfUITextField];
        myTextField.text = AppSession.currentOrderMenu.persons;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:TranslateStr(@"修改人数")
                                                        message:@"this gets covered1" 
                                                       delegate:self 
                                              cancelButtonTitle:TranslateStr(@"取消") 
                                              otherButtonTitles:TranslateStr(@"确定"), nil];
        [alert addSubview:myTextField];
        [myTextField release];  
        [alert show];
        [alert release];
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==alertView.cancelButtonIndex) {
        MyNSLog(@"点击了取消按钮");
    }else{
        UITextField *myTextField = (UITextField *)[alertView viewWithTag:TagOfUITextField];
        [AppSession.currentOrderMenu updatePersonNum:[NSString stringWithFormat:@"%d", [myTextField.text intValue]]];
        postN(@"SysMsg_GuestOrdering_refreshToolBar");      
        postN(@"SysMsg_MyOrderView_refreshToolBar");  
    }
}
- (void)viewDidLoad{
    [super viewDidLoad];
}
- (void)viewDidUnload{
    [super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
	return YES;
}

@end
